﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ElevatorLib
{
    /// <summary>
    /// 将楼层号转化为楼层请求值（楼层值）
    /// 以10层楼为例
    /// 向上请求的楼层值分别为0,1,2,3,4,5,6,7,8,9
    /// 向下请求的楼层值分别为19,18,17,16,15,14,13,12,11,10
    /// </summary>
    public class RequestConvert
    {
        /// <summary>
        /// 楼层值转化为楼层
        /// </summary>
        /// <param name="value">楼层值</param>
        /// <returns></returns>
        public static int ValueToFloorNo(int value)
        {
            if (value >= Building.floorNum)
            {
                return Building.floorNum * 2 - value - 1;
            }
            else
            {
                return value;
            }
        }

        /// <summary>
        /// 楼层转化为楼层值
        /// </summary>
        /// <param name="floorNo">楼层</param>
        /// <param name="upOrDown">请求方向</param>
        /// <returns></returns>
        public static int FloorNoToValue(int floorNo, bool upOrDown)
        {
            if (upOrDown)
            {
                return floorNo;
            }
            else
            {
                return Building.floorNum * 2 - floorNo - 1;
            }
        }

        /// <summary>
        /// 获取楼层值方向
        /// </summary>
        /// <param name="value">楼层值</param>
        /// <returns>请求方向</returns>
        public static bool GetValueDirection(int value)
        {
            if (value >= Building.floorNum)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
